package com.project.erp.dao.contract.trade;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.project.erp.common.dao.HibernateDao;
import com.project.erp.common.utils.Page;
import com.project.erp.model.contract.trade.TradeCusContract;

/**
 * 
 * COPYRIGHT (C) 2013 BY XXX公司

 *  功能模块名：合同-外贸客户合同 

 *  功能描述：外贸客户合同 Dao类

 * @author LiJiaGuo    

 * @version 1.0  

 * @created 2013-12-14 上午10:47:41
 */
@Repository
public class TradeCusContractDao extends HibernateDao<TradeCusContract, Long> {
	/**
	 * 根据id列表删除
	 * @param idsList
	 */
	public void delTradeCusContractBytradeCusContractIds(final List<Long> idsList){
		this.deleteByIdsList(idsList);
	}
	
	/**
	 * 根据条件查询
	 * @tradeCusContract page
	 * @tradeCusContract tradeCusContract
	 * @return
	 */
	public Page<TradeCusContract> getTradeCusContractPageBySearch(Page<TradeCusContract> page,TradeCusContract tradeCusContract){
		List<Criterion> list = new ArrayList<Criterion>();
		
		if(StringUtils.isNotEmpty(tradeCusContract.getInvoiceNo())){
			Criterion invoiceNo = Restrictions.ilike("invoiceNo",tradeCusContract.getInvoiceNo(),MatchMode.ANYWHERE);
			list.add(invoiceNo);
		}
		if(StringUtils.isNotEmpty(tradeCusContract.getCreateUser())){
			Criterion createUser = Restrictions.ilike("createUser",tradeCusContract.getCreateUser(),MatchMode.ANYWHERE);
			list.add(createUser);
		}
		if(tradeCusContract.getStartTime() != null){
			Criterion startDate = Restrictions.ge("createTime", tradeCusContract.getStartTime());
			list.add(startDate);
		}
		
		if(tradeCusContract.getEndTime() != null){
			Criterion endTime = Restrictions.le("createTime",tradeCusContract.getEndTime());
			list.add(endTime);
		}
		
		page = this.findPage(page,list.toArray(new Criterion[list.size()]));
		
		return page;
	}
}
